<template>
  <div class="content-block block-2">
    <div class="info-head">{{ title }}</div>
    <div class="info-content flex flex-wrap align-center">
      <v-chart :option="chartOption" style="width: 400px;height:300px;"></v-chart>
      <div class="table-wrap">
        <el-table
          :data="lists" height="auto"
          :header-cell-style="{
            backgroundColor: themeColor,
            color: 'white'
          }"
        >
          <el-table-column v-for="column in columns" :key="column.prop" v-bind="column"></el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'grid-item-two',
  props: ['title'],
  data () {
    return {
      lists: [
        { type: '城市生活垃圾用于燃料', value: '14893.5', proportion: '20' },
        { type: '电力', value: '253.66', proportion: '80' },
      ],
      columns: [
        { label: '能源类别', prop: 'type' },
        { label: '消费量（吨标准煤）', prop: 'value' },
        { label: '占比（%）', prop: 'proportion' },
      ]
    }
  },
  computed: {
    chartOption () {
      return {
        tooltip: {
          trigger: 'item'
        },
        series: [
          {
            type: 'pie',
            radius: ['30%', '50%'],
            data: this.lists.map((v) => ({
              name: v.type,
              value: v.value
            }))
          }
        ]
      }
    },
    themeColor () {
      return this.$store.state.user.theme
    }
  },
}
</script>

<style lang="scss" scoped>
  .table-wrap {
    width: 650px;
    margin-left: 50px;

    @media screen and (max-width: 1330px) {
      width: 100%;
    }
  }
</style>
